package com.usabb.service.impl;

import com.usabb.api.dto.*;
import com.usabb.domain.HomeStayDO;
import com.usabb.domain.HospitalDO;
import com.usabb.enums.BizTypeEnum;
import com.usabb.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class HomeStayApiServiceImpl implements HomeStayApiService {
    @Autowired
    private HomeStayService homeStayService;
    @Autowired
    private AttachService attachService;
    @Autowired
    private RoundRelationService roundRelationService;
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private AmenityService amenityService;
    @Autowired
    private GuestCaseService guestCaseService;

    @Override
    public HomeStayDO getFullDOById(Long id) {
        HomeStayDO stayDO = homeStayService.selectById(id);
        appendDetail(stayDO);

        return stayDO;
    }

    @Override
    public void appendDetail(HomeStayDO homeStayDO) {
        final Long id = homeStayDO.getId();
        //组装民宿周边信息
        List<RoundTypeDTO> roundTypeDTOS = roundRelationService.getRoundTypeDTOListBy(BizTypeEnum.HOME_STAY, id);
        homeStayDO.setRoundTypes(roundTypeDTOS);

        //组装民宿图片
        AttachesDTO attachesDTO = attachService.getAttachesDTOBy(BizTypeEnum.HOME_STAY, id);
        homeStayDO.setAttaches(attachesDTO);

        //组装关联医院
        final List<HospitalDTO> hospitalDTOS = hospitalService.getDTOListByBizTypeAndBizId(BizTypeEnum.HOME_STAY, id);
        homeStayDO.setHospitals(hospitalDTOS);

        //组装配套设施
        AmenitiesDTO amenitiesDTO = amenityService.getByBizTypeAndBizId(BizTypeEnum.HOME_STAY, id);
        homeStayDO.setAmenities(amenitiesDTO);

        //组装客户感言
        final List<GuestCaseDTO> guestCaseDTOS = guestCaseService.getBy(BizTypeEnum.HOME_STAY, id);
        homeStayDO.setGuestCases(guestCaseDTOS);

    }
}
